package de.karlNet.login.attributeMapper;

import java.util.List;

import javax.naming.NamingException;
import javax.naming.directory.Attributes;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import de.karlNet.sambamanager.ldapModel.LdapObject;

@Component
public class ObjectExtractor {
	@Autowired
	private List<LdapObjectExtractor> extractors;

	public LdapObject extract(Attributes attributes, List<String> objectClasses)
			throws NamingException {
		for (LdapObjectExtractor objectExtractor : extractors) {
			LdapObject resultOfExtraction = objectExtractor.extract(attributes,
					objectClasses);
			if (resultOfExtraction != null) {
				return resultOfExtraction;
			}
		}
		return new LastExtractor().extract(attributes, objectClasses);
	}
}
